package fschmidt.util.java;

import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import java.util.EmptyStackException;


public class ArrayStack<E> extends ArrayList<E> implements Stack<E> {

	public ArrayStack() {}

	public ArrayStack(Collection<E> c) {
		super(c);
	}

	@Override public void push(E item) {
		add(item);
	}

	@Override public E pop() throws EmptyStackException {
		int	len = size();
		if (len == 0)
			throw new EmptyStackException();
		return remove(len - 1);
	}

	@Override public E peek() throws EmptyStackException {
		int	len = size();
		if (len == 0)
			throw new EmptyStackException();
		return get(len - 1);
	}

}
